USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactTypes-Insert]    Script Date: [[20120714223928]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223928]]
-- Description:	Insert record into table [dbo].[ContactTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactTypes-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactTypes-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactTypes-Insert]
	/*@ContactType_RowNumber int =Null OUTPUT , 
	@ContactType_ID uniqueidentifier =Null  , 
	@ContactType_Code varchar(50) =Null  , 
	@ContactType_NameAr varchar(300) =Null  , 
	@ContactType_NameEn varchar(300) =Null  , 
	@ContactType_Notes varchar(max) =Null  , 
	@ContactType_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[ContactTypes](/*[ContactType_ID], [ContactType_Code], [ContactType_NameAr], [ContactType_NameEn], [ContactType_Notes], [ContactType_Search]*/)
	VALUES     (/*@ContactType_ID, @ContactType_Code, @ContactType_NameAr, @ContactType_NameEn, @ContactType_Notes, @ContactType_Search*/)

	/*SELECT @ContactType_RowNumber = [ContactType_RowNumber]
    FROM [dbo].[ContactTypes]
    WHERE  ( [ContactType_ID] =@ContactType_ID )
	AND  ( [ContactType_Code] =@ContactType_Code )
	AND  ( [ContactType_NameAr] =@ContactType_NameAr )
	AND  ( [ContactType_NameEn] =@ContactType_NameEn )
	AND  ( [ContactType_Notes] =@ContactType_Notes )
	AND  ( [ContactType_Search] =@ContactType_Search )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactTypes-update]    Script Date: [[20120714223928]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223928]]
-- Description:	Update record in table [dbo].[ContactTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactTypes-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactTypes-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactTypes-update]
	/*@ContactType_RowNumber int =Null OUTPUT , 
	@ContactType_ID uniqueidentifier =Null  , 
	@ContactType_Code varchar(50) =Null  , 
	@ContactType_NameAr varchar(300) =Null  , 
	@ContactType_NameEn varchar(300) =Null  , 
	@ContactType_Notes varchar(max) =Null  , 
	@ContactType_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[ContactTypes] SET 
		/*[ContactType_ID] =@ContactType_ID, 
		[ContactType_Code] =@ContactType_Code, 
		[ContactType_NameAr] =@ContactType_NameAr, 
		[ContactType_NameEn] =@ContactType_NameEn, 
		[ContactType_Notes] =@ContactType_Notes, 
		[ContactType_Search] =@ContactType_Search*/
		/*WHERE ([ContactType_ID] = @ContactType_ID)*/
	/**/

	/*SELECT @ContactType_RowNumber = [ContactType_RowNumber]
    FROM [dbo].[ContactTypes]
	WHERE ([ContactType_ID] = @ContactType_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactTypes-Insert-Update]    Script Date: [[20120714223928]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223928]]
-- Description:	Insert OR Update record into table [dbo].[ContactTypes]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactTypes-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactTypes-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactTypes-Insert-Update]
	/*@ContactType_RowNumber int =Null OUTPUT , 
	@ContactType_ID uniqueidentifier =Null  , 
	@ContactType_Code varchar(50) =Null  , 
	@ContactType_NameAr varchar(300) =Null  , 
	@ContactType_NameEn varchar(300) =Null  , 
	@ContactType_Notes varchar(max) =Null  , 
	@ContactType_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[ContactTypes] 
					/*WHERE ([ContactType_ID] = @ContactType_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[ContactTypes](/*[ContactType_ID], [ContactType_Code], [ContactType_NameAr], [ContactType_NameEn], [ContactType_Notes], [ContactType_Search]*/)
		VALUES     (/*@ContactType_ID, @ContactType_Code, @ContactType_NameAr, @ContactType_NameEn, @ContactType_Notes, @ContactType_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[ContactTypes] SET 
			/*[ContactType_ID] =@ContactType_ID, 
			[ContactType_Code] =@ContactType_Code, 
			[ContactType_NameAr] =@ContactType_NameAr, 
			[ContactType_NameEn] =@ContactType_NameEn, 
			[ContactType_Notes] =@ContactType_Notes, 
			[ContactType_Search] =@ContactType_Search*/
			/*WHERE ([ContactType_ID] = @ContactType_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @ContactType_RowNumber = [ContactType_RowNumber]
    FROM [dbo].[ContactTypes]
	WHERE ([ContactType_ID] = @ContactType_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactTypes-Delete]    Script Date: [[20120714223928]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223928]]
-- Description:	delete records from table [dbo].[ContactTypes] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactTypes-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactTypes-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactTypes-Delete]
	/*@ContactType_RowNumber int =null  , 
	@ContactType_ID uniqueidentifier =null  , 
	@ContactType_Code varchar(50) =null  , 
	@ContactType_NameAr varchar(300) =null  , 
	@ContactType_NameEn varchar(300) =null  , 
	@ContactType_Notes varchar(max) =null  , 
	@ContactType_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[ContactTypes]
	WHERE /*( [ContactType_RowNumber] = ISNULL(@ContactType_RowNumber, [ContactType_RowNumber]) )
	AND ( [ContactType_ID] = ISNULL(@ContactType_ID, [ContactType_ID]) )
	AND ( [ContactType_Code] like ISNULL(@ContactType_Code, [ContactType_Code]) )
	AND ( [ContactType_NameAr] like ISNULL(@ContactType_NameAr, [ContactType_NameAr]) )
	AND ( [ContactType_NameEn] like ISNULL(@ContactType_NameEn, [ContactType_NameEn]) )
	AND ( [ContactType_Notes] like ISNULL(@ContactType_Notes, [ContactType_Notes]) )
	AND ( [ContactType_Search] like ISNULL(@ContactType_Search, [ContactType_Search]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[ContactTypes-Select]    Script Date: [[20120714223928]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223928]]
-- Description:	select records from table [dbo].[ContactTypes] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[ContactTypes-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[ContactTypes-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[ContactTypes-Select]
	/*@ContactType_RowNumber int =null  , 
	@ContactType_ID uniqueidentifier =null  , 
	@ContactType_Code varchar(50) =null  , 
	@ContactType_NameAr varchar(300) =null  , 
	@ContactType_NameEn varchar(300) =null  , 
	@ContactType_Notes varchar(max) =null  , 
	@ContactType_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[ContactTypes]
	WHERE /*( [ContactType_RowNumber] = ISNULL(@ContactType_RowNumber, [ContactType_RowNumber]) )
	AND ( [ContactType_ID] = ISNULL(@ContactType_ID, [ContactType_ID]) )
	AND ( [ContactType_Code] like ISNULL(@ContactType_Code, [ContactType_Code]) )
	AND ( [ContactType_NameAr] like ISNULL(@ContactType_NameAr, [ContactType_NameAr]) )
	AND ( [ContactType_NameEn] like ISNULL(@ContactType_NameEn, [ContactType_NameEn]) )
	AND ( [ContactType_Notes] like ISNULL(@ContactType_Notes, [ContactType_Notes]) )
	AND ( [ContactType_Search] like ISNULL(@ContactType_Search, [ContactType_Search]) )*/
END
GO
-- =============================================
